from PySide6.QtWidgets import QDockWidget, QWidget, QVBoxLayout
from PySide6.QtCore import Qt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.pyplot as plt
import numpy as np

class VerticalVisualizationDock(QDockWidget):
    dock_area = Qt.RightDockWidgetArea
    def __init__(self, parent=None):
        super().__init__("竖向数据可视化", parent)
        self.setFeatures(QDockWidget.DockWidgetClosable | QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable)
        widget = QWidget()
        layout = QVBoxLayout(widget)
        layout.addWidget(self._create_plot_canvas())
        self.setWidget(widget)


    def _create_plot_canvas(self):
        fig, ax = plt.subplots(figsize=(3, 8))
        y = np.linspace(0, 1000, 100)
        ax.plot(np.random.normal(200, 30, size=100), y, 'r', label='竖向曲线')
        ax.set_ylabel('TVD')
        ax.set_xlabel('数值')
        ax.set_title('竖向数据可视化')
        ax.legend()
        return FigureCanvas(fig)

    # def update_data(self, well_name, df: pd.DataFrame):
    #     self.current_well = well_name
    #     self.data = df
    #
    #     # 示例：假设需要"斜深"作为X轴
    #     if '斜深' in df.columns:
    #         self.plot_widget.plot(
    #             x=df['斜深'],
    #             y=df.drop(columns=['斜深'])  # 绘制所有其他列
    #         )
    #     else:
    #         self.show_error("请包含斜深字段")